﻿using StoreProject.Enum;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StoreProject.Forms.Base
{
    public class ConfigFromFactory
    {
        private Hashtable _cmdList;
        private static ConfigFromFactory cfgCmdFactory = new ConfigFromFactory();

        public static ConfigFromFactory Instance
        {
            get
            {
                if (cfgCmdFactory == null)
                {
                    cfgCmdFactory = new ConfigFromFactory();
                }
                return cfgCmdFactory;
            }
        }

        private ConfigFromFactory()
        {
            _cmdList = new Hashtable();
            _cmdList.Add(ConfigButtonType.ADD, new ADDCommand());
            _cmdList.Add(ConfigButtonType.UPDATE, new UpdateCommand());
            _cmdList.Add(ConfigButtonType.DELETE, new DeleteCommand());
            _cmdList.Add(ConfigButtonType.SAVE, new SaveCommand());
            _cmdList.Add(ConfigButtonType.CANCEL, new ConfigCancelCommand());
            _cmdList.Add(ConfigButtonType.QUERY, new QueryCommand());
            _cmdList.Add(ConfigButtonType.PRINT, new PrintCommand());
            _cmdList.Add(ConfigButtonType.EXPORT, new ExportCommand());
            _cmdList.Add(ConfigButtonType.EXIT, new ConfigExitCommand());

        }

        public IConfigCommand GetCommand(ConfigButtonType cmdType)
        {
            if (this._cmdList != null)
            {
                if (this._cmdList.ContainsKey(cmdType))
                    return (IConfigCommand)_cmdList[cmdType];
            }
            return null;
        }
    }

    public class PrintCommand : IConfigCommand
    {
        #region IConfigCommand 成员

        public void ExecuteCommand(BaseConfigForm configForm)
        {
            configForm.Print();
        }

        #endregion
    }

    public class ExportCommand : IConfigCommand
    {
        #region IConfigCommand 成员

        public void ExecuteCommand(BaseConfigForm configForm)
        {
            configForm.Export();
        }

        #endregion
    }

    public class ADDCommand : IConfigCommand
    {
        #region IConfigCommand 成员

        public void ExecuteCommand(BaseConfigForm configForm)
        {
            configForm.Add();
        }

        #endregion
    }

    public class UpdateCommand : IConfigCommand
    {
        #region IConfigCommand 成员

        public void ExecuteCommand(BaseConfigForm configForm)
        {
            configForm.UpdateData();
        }

        #endregion
    }

    public class DeleteCommand : IConfigCommand
    {
        #region IConfigCommand 成员

        public void ExecuteCommand(BaseConfigForm configForm)
        {
            configForm.Delete();
        }

        #endregion
    }

    public class QueryCommand : IConfigCommand
    {
        #region IConfigCommand 成员

        public void ExecuteCommand(BaseConfigForm configForm)
        {
            configForm.Query();
        }

        #endregion
    }

    public class SaveCommand : IConfigCommand
    {
        #region IConfigCommand 成员

        public void ExecuteCommand(BaseConfigForm configForm)
        {
            configForm.Save();
        }

        #endregion
    }

    public class ConfigExitCommand : IConfigCommand
    {
        #region IConfigCommand 成员

        public void ExecuteCommand(BaseConfigForm configForm)
        {
            configForm.Exit();
        }

        #endregion
    }

    public class ConfigCancelCommand : IConfigCommand
    {
        #region IConfigCommand 成员

        public void ExecuteCommand(BaseConfigForm configForm)
        {
            configForm.Cancel();
        }

        #endregion
    }
}
